package com.uam.core.entity.exception;

import com.uam.core.entity.enums.TrackErrorCode;
import com.uam.core.entity.uitls.Result;

/**
 * 服务异常类
 *
 * @author heguanglong
 * @date 2018/04/23
 */
public class UamServerException extends RuntimeException {

    private static final long serialVersionUID = 1001L;

    /**
     * 返回对象，该对象中包含异常原因，异常码，成功等信息
     */
    private Result result;

    /**
     * 公共类，初始化返回对象，服务器异常，一般需要后面进一步处理
     */
    public UamServerException() {
        this.result = new Result();
    }

    public UamServerException(Result result) {
        this.result = new Result();
        this.result.setStatus(result.getStatus());
        this.result.setMessage(result.getMessage());
    }




    public UamServerException(TrackErrorCode paramError) {
        this.result=new Result();
        this.result.setStatus(paramError.getErrorCode());
        this.result.setMessage(paramError.getErrorMessage());
    }

    public UamServerException(String msg) {
        this.result=new Result(msg,null);
    }


    /**
     * @author heguanglong
     * @date 2019/11/15 下午6:12
     * @description 设置返回code
     */
    public UamServerException setCode(int code) {
        this.result.setStatus(code);
        return this;
    }

    /**
     * @return 设置返回信息
     * @author heguanglong
     * @date 2018/04/23
     */
    public UamServerException setMessage(String message) {
        if (message != null) {
            this.result.setMessage(message);
        }
        return this;
    }



    /**
     * @return 设置返回信息
     * @author heguanglong
     * @date 2018/04/23
     */
    public UamServerException setAddMessage(String message) {
        if (message != null) {
            this.result.setMessage(this.result.getMessage() + "," + message);
        }
        return this;
    }

    /**
     * @return 返回异常对象信息
     * @author heguanglong
     * @date 2018/04/23
     */
    public Result getResult() {
        return this.result;
    }
}
